package com.itheima.springboottlias.controller;

import com.itheima.springboottlias.common.utils.AliOSSUtils;
import com.itheima.springboottlias.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author Taotao
 * @date 2023/7/16 10:09
 * @desciption: 文件上传
 */
@RestController
@Slf4j
public class UploadController {
    @Autowired
    private AliOSSUtils aliOSSUtils;
    @PostMapping("/upload")
    public Result upload(@RequestParam MultipartFile image, String name, Integer age) throws IOException {
        log.info("参数: {} ,{} , {}", image, name, age);
//        String originalFilename = image.getOriginalFilename();
//        String s = UUID.randomUUID().toString();
//        String substring = image.getOriginalFilename().substring(originalFilename.lastIndexOf("."));

        String upload = aliOSSUtils.upload(image);
        return Result.success(upload);

//        image.transferTo(new File("D:\\Dev\\WebProjectCode\\TliasWebManage\\nginx-1.22.0-tlias\\html\\image\\"+s+substring));
//        return Result.success("http://localhost:90/image/"+s+substring);
    }
}
